<% add_decidim_page_title(t(".title")) %>
<div class="item_show__header">
  <h1 class="item_show__header-title">
    <div>
      <%= t(".title") %>
      <span id="js-selected-moderated_users-count" class="component-counter " title="<%= t("decidim.admin.moderated_users.index.selected") %>"></span>
    </div>

    <div class="flex items-center gap-x-4">
      <%= render partial: "bulk-actions" %>
      <div class="card__filter">
        <%= link_to t("decidim.admin.moderated_users.tabs.unblocked"), moderated_users_path %>
        |
        <%= link_to t("decidim.admin.moderated_users.tabs.blocked"), moderated_users_path(blocked: true) %>
      </div>
    </div>
  </h1>
</div>

<%= admin_filter_selector(:moderated_users) %>
<div class="table-stacked">
  <table class="table-list">
    <thead>
    <tr>
      <th><%= check_box_tag "moderated_users_bulk", "all", false, class: "js-check-all" %></th>
      <th><%= t(".name") %></th>
      <th><%= t(".nickname") %></th>
      <th><%= t(".reason") %></th>
      <th><%= sort_link(query, :created_at, t("models.moderation.fields.created_at", scope: "decidim.moderations")) %></th>
      <th><%= sort_link(query, :report_count, t(".reports"), default_order: :desc) %></th>
      <th><%= t(".actions.title") %></th>
    </tr>
    </thead>
    <tbody>
    <% @moderated_users.each do |moderation| %>
      <tr data-id="<%= moderation.id %>">
        <td data-label="">
          <%= check_box_tag "user_ids_s[]", moderation.user.id, false, class: "js-check-all-moderated_users js-moderated_user-list-check js-moderated_user-id-#{moderation.user.id}" %>
        </td>

        <% if moderation.user.nickname.present? %>
          <td data-label="<%= t(".name") %>">
            <%= link_to moderation.user.name, decidim.profile_path(moderation.user.nickname) %>
          </td>
          <td data-label="<%= t(".nickname") %>">
            <%= link_to moderation.user.nickname, decidim.profile_path(moderation.user.nickname) %>
          </td>
        <% else %>
          <td data-label="<%= t(".name") %>">
            <%= moderation.user.name %>
          </td>
          <td data-label="<%= t(".nickname") %>">
            <%= moderation.user.nickname %>
          </td>
        <% end %>

        <td data-label="<%= t(".reason") %>">
          <% reports = moderation.reports.map { |report| render "report", report: } %>
          <%= safe_join(reports, ", ") %>
        </td>

        <td data-label="<%= t("models.moderation.fields.created_at", scope: "decidim.moderations") %>">
          <%= l moderation.created_at, format: :decidim_short %>
        </td>

        <td data-label="<%= t(".reports") %>">
          <%= moderation.report_count %>
        </td>

        <td class="table-list__actions" data-label="<%= t(".actions.title") %>">
          <button type="button" data-controller="dropdown" data-target="actions-user-<%= moderation.user.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: moderation.user.nickname) %>">
            <%= icon "more-fill", class: "text-secondary" %>
          </button>

          <div class="inline-block relative">
            <ul id="actions-user-<%= moderation.user.id %>" class="dropdown dropdown__action" aria-hidden="true">
              <% if !moderation.user.blocked? && allowed_to?(:unreport, :moderate_users, user: moderation.user) %>
                <li class="dropdown__item">
                  <%= link_to ignore_moderated_user_path(id: moderation), method: :put, class: "dropdown__button" do %>
                    <%= icon "arrow-go-back-line" %>
                    <%= t(".actions.unreport") %>
                  <% end %>
                </li>
              <% end %>

              <% if allowed_to?(:block, :moderate_users, user: moderation.user) %>
                <hr>

                <% if moderation.user.blocked? %>
                  <li class="dropdown__item">
                    <%= link_to user_block_path(user_id: moderation.user.id), method: :delete, class: "dropdown__button" do %>
                      <%= icon "refresh-line" %>
                      <%= t(".actions.unblock") %>
                    <% end %>
                  </li>
                <% else %>
                  <li class="dropdown__item">
                    <%= link_to new_user_block_path(user_id: moderation.user.id), class: "dropdown__button" do %>
                      <%= icon "lock-2-line" %>
                      <%= t(".actions.block") %>
                    <% end %>
                  </li>
                <% end %>
              <% end %>
            </ul>
          </div>
        </td>
      </tr>
    <% end %>
    </tbody>
  </table>
</div>
<%= decidim_paginate @moderated_users %>
